<?php

class Users extends MY_Controller{
	private $status	= TRUE;
	private $token	= '';
	
	function __construct(){
		parent::__construct();
		$this->load->database();
		Sys::loadLanguage($this->params['lang'],'panel');
	}

	public function _remap($method, $params){
		$res = $this->checkAccessToken();
		
		$this->load->model('user_model');
		$info = $this->user_model->getInfoUser($this->params);
		$this->params['usr_info'] = $info['user'];
		
		if($res && $this->params['usr_info']['status']==1){
			$this->load->model('user_model');
			$info = $this->user_model->getInfoUser($this->params);
			$this->params['usr_info'] = $info['user'];		
			
			if($this->params['usr_info']['tipo']==='usuario' || $this->params['usr_info']['tipo']==='admin'){
				switch ($method) {
					case 'index':
							header('Location:'.Sys::$url_base.$this->params['lang_url'].'panel');
					break;
					
					//	METODOS PARA PELICULAS	
					case 'search':
							$this->search_film($method,$params);
					break;
					case 'admin':
							$this->admin($method,$params);
					break;
					case 'add':
							$this->add_film($method,$params);
					break;
					case 'edit':
							$this->add_film($method,$params);
					break;
					case 'save':
							$this->save_film($method,$params);
					break;
					case 'update_film':
							$this->update_film($method,$params);
					break;
					
					//	METODOS PARA SERIES
					
					case 'search_serie':
							$this->search_serie($method,$params);
					break;
					case 'admin_serie':
							$this->admin_serie($method,$params);
					break;
					case 'add_episode':
							$this->add_episode($method,$params);
					break;
					case 'save_episode':
							$this->save_episode($method,$params);
					break;
					case 'edit_episode':
							$this->add_episode($method,$params);
					break;
					case 'update_episode':
							$this->update_episode($method,$params);
					break;
					
					// METODOS PARA LA INFORMACION DEL USUARIO
					case 'edit_info':
							$this->user($method,$params);
					break;
					case 'update_info':
							$this->update($method,$params);
					break;
					
					default:
						show_404();
					break;
				}
			}else header('Location:'.Sys::$url_base.$this->params['lang_url'].'panel');
			
		}
		else if(isset($_COOKIE["p_goto"])){ //redireccionar a alguna url despues de logearse
			$url = $_COOKIE["p_goto"];
			setcookie('p_goto', '', time()-1200, '/');
			header("Location: ".$url);
		}else{
	    	header('Location:'.Sys::$url_base.$this->params['lang_url'].'');
		}
	}

	/**
	 * REALIZA LA BUSQUEDA DE PELICULAS PARA EL USUARIO QUE DESEA AGREGAR LINKS PARA UNA.
	 * 
	 * @param $method			Metodo que llama la funcion
	 * @param $params			Parametros del Segmento de la URL u otros
	 */
	private function admin($method,$params){
		//	CARGA LOS CSS
		// $this->carabiner->css('dev/libs/tipsy.css');
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/libs/jquery.treeview.css');
		$this->carabiner->css('dev/panel/style.css');
		// $this->carabiner->css('dev/panel/films/style_admin_films.css');
		$this->carabiner->css('dev/panel/series/style_admin_series.css');
		
		//	CARGA LOS JS
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/jquery.treeview.js'),
					array('dev/libs/tipsy.js'),
					array('dev/panel/general.js'),
					array('dev/panel/useradmin.js')
				);
		$this->carabiner->js($js);
		
		$this->params['lang_txt_seccion']	= lang('txt_user_admin_film');
		$this->params['selected_menu10']	= 'mnu-selected';
		$this->params['selected_submenu31']	= 'submnu-selected';
		
		$this->params['method']	 = 'admin';
		$this->params['method2'] = 'edit';
		$this->params['title'] = 'Editar mis links';
		$show_error = FALSE;
		
		$this->params['q'] = isset($this->params['q']) ? $this->params['q'] : '';
		$this->params['userFilm']	= TRUE;
		
		if(isset($this->params['q'])){	
			$this->load->library('pagination');
			
			$this->params['result_items_per_page'] 	= 40;
			$this->params['result_page'] 			= 0;
			//$this->params['type']					= 'p';
			
			if(isset($this->params['pag'])){
				if($this->params['pag'] % $this->params['result_items_per_page'] == 0)
					$this->params['result_page'] = ($this->params['pag']/$this->params['result_items_per_page']);
			}

			$this->params['id_usuario'] = $this->params['usr_info']['id_usuario'];
			
			// echo '<pre>';
			// var_dump($this->params);exit;
			// echo '</pre>';
	
			$this->load->model("search_model");
			$this->params['resultados'] = $this->search_model->getUserMisPeliculas($this->params);
			
			if(count($this->params['resultados']['result_search']) > 0)
				$this->params['list'] = $this->params['resultados'];
			else{
				$show_error = TRUE;
				$this->params['msg'] = 'Sin Resultados';
				$this->params['seo']['description'] = $this->params['msg'];
			}
		}
		$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> ''
				);
		
		if($show_error){
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);	
		}
		else{			
			// $this->params['aside_extra'] = $this->load->view('interface/panel/films/aside_buttons', $this->params, true);
			$this->load->view('interface/header',$this->params);
			$this->load->view('interface/panel/content',$this->params);
			$this->load->view('interface/panel/user/search_film',$this->params);
		}
		
		if($this->params['usr_info']['tipo']==='admin')
			$this->load->view('interface/panel/aside',$this->params);
		elseif($this->params['usr_info']['tipo']==='usuario')
			$this->load->view('interface/panel/user/aside',$this->params);
		
		$this->load->view('interface/footer',$this->params);
		
	}


	/**
	 * REALIZA LA BUSQUEDA DE PELICULAS PARA EL USUARIO QUE DESEA AGREGAR LINKS PARA UNA.
	 * 
	 * @param $method			Metodo que llama la funcion
	 * @param $params			Parametros del Segmento de la URL u otros
	 */
	private function search_film($method,$params){
		//	CARGA LOS CSS
		// $this->carabiner->css('dev/libs/tipsy.css');
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/libs/jquery.treeview.css');
		$this->carabiner->css('dev/panel/style.css');
		// $this->carabiner->css('dev/panel/films/style_admin_films.css');
		$this->carabiner->css('dev/panel/series/style_admin_series.css');

		//	CARGA LOS JS
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/jquery.treeview.js'),
					array('dev/libs/tipsy.js'),
					array('dev/panel/general.js'),
					array('dev/panel/useradmin.js')
				);
		$this->carabiner->js($js);
		
		$this->params['lang_txt_seccion']	= lang('txt_user_search_film');
		$this->params['selected_menu10']		= 'mnu-selected';
		$this->params['selected_submenu30']	= 'submnu-selected';
		$this->params['title'] = 'Agregar mis links';
		
		$this->params['method']		= 'search';
		$this->params['method2']	= 'add';
		
		$show_error = FALSE;
		
		if(isset($this->params['q'])){
			$this->load->library('pagination');
			
			$this->params['result_items_per_page'] 	= 40;
			$this->params['result_page'] 			= 0;
			$this->params['type']					= 'p';
			
			if(isset($this->params['pag'])){
				if($this->params['pag'] % $this->params['result_items_per_page'] == 0)
					$this->params['result_page'] = ($this->params['pag']/$this->params['result_items_per_page']);
			}
	
			$this->load->model("search_model");
			$this->params['resultados'] = $this->search_model->search2($this->params);
			
			if(count($this->params['resultados']['result_search']) > 0)
				$this->params['list'] = $this->params['resultados'];
			else{
				$show_error = TRUE;
				$this->params['msg'] = lang('p_no_results');
				$this->params['seo']['description'] = $this->params['msg'];
			}
		}
		$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> ''
				);
		
		if($show_error){
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);	
		}
		else{			
			// $this->params['aside_extra'] = $this->load->view('interface/panel/films/aside_buttons', $this->params, true);
			$this->load->view('interface/header',$this->params);
			$this->load->view('interface/panel/content',$this->params);
			$this->load->view('interface/panel/user/search_film',$this->params);
		}
		
		if($this->params['usr_info']['tipo']==='admin')
			$this->load->view('interface/panel/aside',$this->params);
		elseif($this->params['usr_info']['tipo']==='usuario')
			$this->load->view('interface/panel/user/aside',$this->params);
		
		$this->load->view('interface/footer',$this->params);
		
	}

	/**
	 * MUESTRA EL FORMULARIO PARA AGREGAR O EDITAR PELICULAS
	 * 
	 * @param $method			Metodo que llama la funcion
	 * @param $params			Parametros del Segmento de la URL u otros
	 */
	public function add_film($method = '', $params=''){
		
		// CARGA LOS CSS
		// $this->carabiner->css('dev/libs/superbox.css');
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/panel/style.css');
		$this->carabiner->css('dev/panel/style_form.css');
		
		// CARGA LOS JS
		$js	= array(
					array('dev/libs/jquery.js'),
					// array('dev/libs/superbox.jquery.js'),
					array('dev/libs/tipsy.js'),
					array('dev/panel/general.js'),
					// array('dev/panel/films/films.js'),
					array('dev/panel/films/films2.js')
				);
		$this->carabiner->js($js);
		
		// SIRVE PARA INDICAR SI EXISTE ALGUN ERROR
		$show_error = FALSE;
		
		// SI AGREGA O GUARDA UNA PELICULA
		if($method === 'add' || $method === 'save'){
			
			// TITULO DE LA SECCION
			$this->params['lang_txt_seccion'] = lang('txt_seccion_films_add');
			
			$this->params['languaje']		= '';
			$this->params['subtitle']		= '';
			$this->params['format_film']	= '';
			$this->params['quality']		= '';
			$this->params['duration']		= '';
			$this->params['size'] 			= '';
			
			$this->params['server_film']	= '';
			$this->params['url_file']		= '';
			$this->params['url_subtitle'] 	= '';
			
			//	OBTIENE LAS CATEGORIAS EXISTENTES
			$categories = $this->db->select('id_categoria, nombre')->from('categorias')->where('calidad',1)->order_by('nombre')->get();
			$this->params['categories'] = $categories->result_array();
			
			//	OBTIENE LOS SERVIDORES ALMACENADOS
			$this->db->select('id_servidor, nombre')->from('servidores');
			$servers = $this->db->get();
			$this->params['servers'] = $servers->result_array();
			
			// var_dump($this->params);exit;
			// SI EXISTE ALGUN MENSAJE
			if (isset($params['msg_action'])){
				$this->params['class_msg']		= 'msg-ok';
				$this->params['msg_action']	= $params['msg_action'];
			}
	
			// INDICA EL MENU PADRE Y EL SUBMENU QUE SERAN SELECCIONADOS
			$this->params['selected_menu10']		= 'mnu-selected';
			$this->params['selected_submenu30']	= 'submnu-selected';

			// EN CASO DE CARGAR EL FORMULARIO SE TIENEN QUE INDICAR ESTOS PARAMETROS LOS CUALES SERAN PARTE DEL ACTION DEL FORMULARIO
			$this->params['controller'] 	= 'users/';
			$this->params['method'] 		= 'save/';
			$this->params['id']				= $params[0];
			$this->params['idh']			= '';
			
			$this->params['seo'] = array(
				'title' 		=> ''.Sys::$title_web,
				'description' 	=> ''
			);
		
			//	OBTIENE LOS SERVIDORES ALMACENADOS
			$this->db->select('id_servidor, nombre')->from('servidores');
			$servers = $this->db->get();
			$this->params['servers'] = $servers->result_array();
		}
		// SI SE EDITA O ACTUALIZA UNA PELICULA
		else if($method === 'edit' || $method === 'update_film'){
			
			// ASIGNA EL ID DE LA PELICULA
			$this->params['id_film'] = $params[0];
			$this->params['id_phash'] = $params[1];
			
			// VALIDA LOS PARAMETROS DE LA PELICULA A EDITAR
			$response_errors = $this->validate('get_film');
			
			if($this->status){
				$this->params['id_usuario'] = $this->params['usr_info']['id_usuario'];
				// CARGA EL MODEL FILMS_MODEL PARA OBTENER LA INFORMACION DE LA PELICULA A EDITAR
				$this->load->model('user_upload_model');
				$info_movie = $this->user_upload_model->getInfoFilm($this->params);
				
				// SI EXISTE LA INFORMACION DE LA PELICULA
				if(is_array($info_movie)){
					
					// TITULO DE LA SECCION
					$this->params['lang_txt_seccion'] = lang('txt_seccion_films_edit');

					$this->params['languaje']		= $info_movie[0]['language'];
					$this->params['subtitle']		= $info_movie[0]['subtitle'];
					$this->params['format_film']	= $info_movie[0]['format_film'];
					$this->params['quality']		= $info_movie[0]['quality'];
					$this->params['duration']		= $info_movie[0]['duration'];
					$this->params['size'] 			= $info_movie[0]['size'];
					$this->params['url_file']		= $info_movie[0]['url_file'];
					$this->params['url_subtitle'] 	= $info_movie[0]['url_subtitle'];
					
					$this->params['server_film']	= $info_movie[0]['id_servidor'];
					
					//	OBTIENE LAS CATEGORIAS EXISTENTES
					$categories = $this->db->select('id_categoria, nombre')->from('categorias')->where('calidad',1)->order_by('nombre')->get();
					$this->params['categories'] = $categories->result_array();
					
					// 	QUERY PARA OBTENER LOS SERVIDORES EXISTENTEN
					$this->db->select('id_servidor, nombre')->from('servidores');
					$servers = $this->db->get();
					$this->params['servers'] = $servers->result_array();
					
					// SI EXISTE ALGUN MENSAJE
					if (isset($params['msg_action'])){
						$this->params['class_msg']		= 'msg-ok';
						$this->params['msg_action']	= $params['msg_action'];
					}
		
					// INDICA EL MENU PADRE Y EL SUBMENU QUE SERAN SELECCIONADOS
					$this->params['selected_menu10']		= 'mnu-selected';
					$this->params['selected_submenu31']	= 'submnu-selected';
		
					// EN CASO DE CARGAR EL FORMULARIO SE TIENEN QUE INDICAR ESTOS PARAMETROS LOS CUALES SERAN PARTE DEL ACTION DEL FORMULARIO
					$this->params['controller'] 	= 'users/';
					$this->params['method'] 		= 'update_film/';
					$this->params['id']				= $this->params['id_film'];
					$this->params['idh']			= '/'.$this->params['id_phash'];
					
					$this->params['seo'] = array(
						'title' 		=> ''.Sys::$title_web,
						'description' 	=> ''
					);
				}
				else{
					// SI NO EXISTE LA PELICULA QUE SE DESEA EDITAR
					$show_error = TRUE;
					$this->params['msg'] = lang('txt_films_id_update_error');
				}
			}
			else{
				// SI EXISTE ALGUN ERRO DE VALIDACIO DE PARAMETROS
				$show_error = TRUE;
				$this->params['msg'] = implode(',', $response_errors);
			}			
		}

		// SI EXISTE UN ERROR LOS MUESTRA
		if($show_error){
			$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> $this->params['msg']
				);
			
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
		}
		else{

			// var_dump('<pre>',$this->params, '</pre>');exit;

			$this->params['aside_extra'] = $this->load->view('interface/panel/films/aside_buttons', $this->params, true);
			$this->load->view('interface/header',$this->params);
			$this->load->view('interface/panel/content',$this->params);
			$this->load->view('interface/panel/user/form_user_add_film',$this->params);
		}
		
		if($this->params['usr_info']['tipo']==='admin')
			$this->load->view('interface/panel/aside',$this->params);
		elseif($this->params['usr_info']['tipo']==='usuario')
			$this->load->view('interface/panel/user/aside',$this->params);
		
		$this->load->view('interface/footer',$this->params);
	}

	/**
	 * GUARDA LA INFORMACION ENVIADA DEL FORMULARIO DE UNA PELICULA.
	 */
	public function save_film($method = '', $params=''){
		
		// VALIDA LOS PARAMETROS DE LA PELICULA A GUARDAR
		$response_errors = $this->validate('add_film');
		

		// var_dump('<pre>', $this->params, '</pre>');exit;

		// SI NO EXISTEN ERRORES DE VALIDACION DE PARAMETROS
		if($this->status == TRUE){
			$this->params['id_film'] = $params[0];
			// // CARGA EL MODEL FILMS_MODEL PARA GUARDAR LA INFORMACION DE LA PELICULA
			$this->load->model('user_upload_model');
			$film = $this->user_upload_model->saveInfoFilm($this->params);
			
			$error = FALSE;
			
			if($film['id_phash'] !== FALSE){
				$this->add_film('save',array($this->params['id_film'],'msg_action'=>lang('txt_film_save_ok')));
			}
			else{
				$error = TRUE;
				$this->params['msg'] = $film['msg'];
			}
				
		}else{
			// SI EXISTEN ERRORES DE VALIDACION DE PARAMETROS
			$error = TRUE;
			$this->params['msg'] = implode(',', $response_errors);
		}
		
		
		if($error){
			
			$this->carabiner->css('dev/style.css');
			$this->carabiner->css('dev/panel/style.css');
			
			$js	= array(
						array('dev/libs/jquery.js'),
						array('dev/libs/tipsy.js'),
						array('dev/panel/general.js')
					);
			
			$this->carabiner->js($js);
			
			$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> $this->params['msg']
				);
			
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
			
			if($this->params['usr_info']['tipo']==='admin')
				$this->load->view('interface/panel/aside',$this->params);
			elseif($this->params['usr_info']['tipo']==='usuario')
				$this->load->view('interface/panel/user/aside',$this->params);
			
			$this->load->view('interface/footer',$this->params);
			
		}
	}


	/**
	 *	ACTUALIZA LA INFORMACION DE PELICULA
	 * 
	 * 	@param string $method			METODO QUE LLAMA LA FUNCION
	 * @param array $params				Parametros del Segmento de la URL u otros
	 */
	public function update_film($method, $params=''){
		
		// VALIDA LOS PARAMETROS DEPENDIENDO QUE SE GUARDARA
		$response_errors = $this->validate('add_film');
		
		// INDICA SI EXISTE ALGUN ERROR
		$show_error = FALSE;
		
		// SI NO EXISTE ERRORES EN LOS PARAMETROS VALIDADOS
		if($this->status == TRUE){
				
			$this->params['id_film'] = $params[0];
			$this->params['id_phash'] = $params[1];

			$this->load->model('user_upload_model');
			$film = $this->user_upload_model->updateInfoFilm($this->params);

			if($film['id_phash'] !== FALSE)
				$this->add_film('update_film',array($this->params['id_film'], $this->params['id_phash'], 'msg_action'=>lang('txt_user_update_info_ok')));
			else{
				$show_error = TRUE;
				$this->params['msg'] = $film['msg'];
				$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> $this->params['msg']
				);
			}
		}else{
			// SI EXISTEN ERRORES DE VALIDACION DE LOS PARAMETROS
			$show_error = TRUE;
			$this->params['msg'] = implode(',', $response_errors);
			$this->params['seo'] = array(
				'title' 		=> ''.Sys::$title_web,
				'description' 	=> $this->params['msg']
			);
		}
		
		// SI EXISTE UN ERROR LO MUESTRA
		if($show_error){
			$this->carabiner->css('dev/style.css');
			$this->carabiner->css('dev/panel/style.css');
			
			$js	= array(
						array('dev/libs/jquery.js'),
						array('dev/panel/general.js')
					);
					
			$this->carabiner->js($js);
					
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
		
			if($this->params['usr_info']['tipo']==='admin')
				$this->load->view('interface/panel/aside',$this->params);
			elseif($this->params['usr_info']['tipo']==='usuario')
				$this->load->view('interface/panel/user/aside',$this->params);
			
			$this->load->view('interface/footer',$this->params);
		}
	}

	// -----------------------------------------------------------------------------------------------------
	
	/**
	 * 	MUESTRA UN LISTADO DE LAS SERIES PARA PODER AGERGAR INFORMACION
	 * 	DE UN EPISODIO
	 * 
	 * 	@param string $method 			METODO QUE LLAMA LA FUNCION
	 * 	@param array $params			PARAMETROS QUE RECIBE, PUEDEN SER SEGMENTOS DE LA URL
	 */
	public function search_serie($method='', $params=''){
			
		//	TITULO DE LA SECCION
		$this->params['lang_txt_seccion'] = lang('txt_user_search_serie');
		
		//	CARGA LOS CSS
		$this->carabiner->css('dev/libs/superbox.css');
		$this->carabiner->css('dev/libs/jquery.treeview.css');
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/panel/style.css');
		$this->carabiner->css('dev/panel/series/style_admin_series.css');
		
		//	CARGA LOS JS
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/jquery.treeview.js'),
					array('dev/libs/tipsy.js'),
					array('dev/libs/superbox.jquery.js'),
					array('dev/panel/general.js'),
					array('dev/panel/series/admin.js')
				);
		$this->carabiner->js($js);
		
		//	CARGA LA LIBRERIA DE PAGINACION Y ASIGNA LA CONFIG
		$this->load->library('pagination');
		$this->params['result_items_per_page'] = 20;
		$this->params['result_page'] = 0;
		
		//	SI EXISTE EL PARAMETRO DE LA PAGINA A MOSTRAR
		if(isset($this->params['pag'])){
			if($this->params['pag'] % $this->params['result_items_per_page'] == 0)
				$this->params['result_page'] = ($this->params['pag']/$this->params['result_items_per_page']);
		}
		
		//	CARGA EL MODELO SERIES_MODEL PARA OBTENER LAS SERIES CON SUS TEMPORADAS Y CAPITULOS
		$this->load->model('series_model');
		$res_series = $this->series_model->getSeriesFull($this->params);
		
		if(is_array($res_series['series'])){
			$this->params['list'] = $res_series;
		}

		// INDICA EL MENU PADRE Y EL SUBMENU QUE SERAN SELECCIONADOS
		$this->params['selected_menu11']	= 'mnu-selected';
		$this->params['selected_submenu32']	= 'submnu-selected';
		
		$this->params['seo'] = array(
			'title' 		=> ''.Sys::$title_web,
			'description' 	=> ''
		);
		
		// $this->params['aside_extra'] = $this->load->view('interface/panel/films/aside_buttons', $this->params, true);
		$this->load->view('interface/header',$this->params);
		$this->load->view('interface/panel/content',$this->params);
		$this->load->view('interface/panel/user/search_series',$this->params);
		
		if($this->params['usr_info']['tipo']==='admin')
			$this->load->view('interface/panel/aside',$this->params);
		elseif($this->params['usr_info']['tipo']==='usuario')
			$this->load->view('interface/panel/user/aside',$this->params);
		
		$this->load->view('interface/footer',$this->params);
		
	}
	
	/**
	 * REALIZA LA BUSQUEDA SERIES QUE TIENE AGREGADAS EL USUARIO
	 * 
	 * @param $method			Metodo que llama la funcion
	 * @param $params			Parametros del Segmento de la URL u otros
	 */
	private function admin_serie($method,$params){
		//	CARGA LOS CSS
		// $this->carabiner->css('dev/libs/tipsy.css');
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/libs/jquery.treeview.css');
		$this->carabiner->css('dev/panel/style.css');
		// $this->carabiner->css('dev/panel/films/style_admin_films.css');
		$this->carabiner->css('dev/panel/series/style_admin_series.css');


		//	CARGA LOS JS
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/jquery.treeview.js'),
					array('dev/libs/superbox.jquery.js'),
					array('dev/libs/tipsy.js'),
					array('dev/panel/general.js'),
					array('dev/panel/useradmin.js')
				);
		$this->carabiner->js($js);
		
		$this->params['lang_txt_seccion']	= lang('txt_user_admin_serie');
		$this->params['selected_menu11']	= 'mnu-selected';
		$this->params['selected_submenu33']	= 'submnu-selected';
		
		$this->params['method']	 = 'admin_serie';
		$this->params['method2'] = 'edit_episode';
		$this->params['title'] = 'Editar mis links';
		$show_error = FALSE;
		
		$this->params['q'] = isset($this->params['q']) ? $this->params['q'] : '';
		
		if(isset($this->params['q'])){	
			$this->load->library('pagination');
			
			$this->params['result_items_per_page'] 	= 40;
			$this->params['result_page'] 			= 0;
			$this->params['type']					= 's';
			
			if(isset($this->params['pag'])){
				if($this->params['pag'] % $this->params['result_items_per_page'] == 0)
					$this->params['result_page'] = ($this->params['pag']/$this->params['result_items_per_page']);
			}

			$this->params['id_usuario'] = $this->params['usr_info']['id_usuario'];
			$this->params['userSerie']	= TRUE;
	
			$this->load->model("search_model");
			$this->params['resultados'] = $this->search_model->getUserMisSeries($this->params);
			
			if(count($this->params['resultados']['result_search']) > 0)
				$this->params['list'] = $this->params['resultados'];
			else{
				$show_error = TRUE;
				$this->params['msg'] = 'Aun no has agregado tus Episodios o No hubo resultados para la busqueda realizada';
				$this->params['seo']['description'] = $this->params['msg'];
			}
		}
		$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> ''
				);
		
		if($show_error){
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);	
		}
		else{			
			// $this->params['aside_extra'] = $this->load->view('interface/panel/films/aside_buttons', $this->params, true);
			$this->load->view('interface/header',$this->params);
			$this->load->view('interface/panel/content',$this->params);
			$this->load->view('interface/panel/user/admin_serie',$this->params);
		}
		
		if($this->params['usr_info']['tipo']==='admin')
			$this->load->view('interface/panel/aside',$this->params);
		elseif($this->params['usr_info']['tipo']==='usuario')
			$this->load->view('interface/panel/user/aside',$this->params);
		
		$this->load->view('interface/footer',$this->params);
		
	}
	
	/**
	 * MUESTRA EL FORMULARIO PARA AGREGAR UN EPISODIO
	 * 
	 * @param $method			Metodo que llama la funcion
	 * @param $params			Parametros del Segmento de la URL u otros
	 */
	public function add_episode($method = '', $params=''){
			
		// CARGA LOS CSS
		$this->carabiner->css('dev/libs/superbox.css');
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/panel/style.css');
		$this->carabiner->css('dev/panel/style_form.css');
		
		// CARGA LOS JS
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/superbox.jquery.js'),
					array('dev/libs/tipsy.js'),
					array('dev/panel/general.js'),
					// array('dev/panel/series/series.js'),
					array('dev/panel/films/films2.js')
				);
		$this->carabiner->js($js);
		
		//	VARIABLE QUE SIRVE PARA INDICAR SI EXISTE ALGUN ERROR DE VALIDACION DE LOS PARAMETROS
		$show_error = FALSE;
		
		// SI SE AGREGA O GUARDA UN EPISODIO
		if($method === 'add_episode' || $method === 'save_episode'){
			
			// ASIGNA EL ID DE LA TEMPORADA
			$this->params['episode'] = $params[0];
			$this->params['idh'] = '';
			
			// OBTIENE EL TOTAL DE TEMPORADAS QUE EXISTE CON EL ID DE LA TEMPORADA
			$this->db->select('id_capitulo')->from('series_capitulos')->where('id_capitulo',$this->params['episode']);
			$total = $this->db->count_all_results();
			
			// SI EXISTE LA TEMPORADA
			if($total==1){
				
				$params['t'] = isset($params['t']) ? $params['t'] : 0;
				
				$this->params['id_usuario'] = $this->params['usr_info']['id_usuario'];
				/*$this->db->select('id_capitulo')->from('series_capitulos_fuentes')->where(array('id_capitulo'=>$this->params['episode'], 'id_usuario'=>$this->params['id_usuario']));
				$total = $this->db->count_all_results();
				if($total==0 || $params['t']==1){*/

					// TITULO DE LA SECCION
					$this->params['lang_txt_seccion'] = lang('txt_seccion_serie_episode_add');
	
					$this->params['format_episode']	= '';
					$this->params['quality']		= '';
					$this->params['duration']		= '';
					$this->params['size']			= '';
					$this->params['languaje']		= '';
					$this->params['subtitles']		= '';
					
					$this->params['url_file']		= '';
					$this->params['url_subtitle']	= '';
					$this->params['server']			= '';
		
					// SI EXISTE ALGUN MENSAJE
					if (isset($params['msg_action'])){
						$this->params['class_msg']	= 'msg-ok';
						$this->params['msg_action']	= $params['msg_action'];
					}
		
					// INDICA EL MENU PADRE Y EL SUBMENU QUE SERAN SELECCIONADOS
					$this->params['selected_menu11']		= 'mnu-selected';
					$this->params['selected_submenu32']	= 'submnu-selected';
		
					// EN CASO DE CARGAR EL FORMULARIO SE TIENEN QUE INDICAR ESTOS PARAMETROS LOS CUALES SERAN PARTE DEL ACTION DEL FORMULARIO
					$this->params['controller'] 	= 'users/';
					$this->params['method'] 		= 'save_episode/';
					$this->params['id']				= $this->params['episode'];
		
					$this->params['seo'] = array(
						'title' 		=> ''.Sys::$title_web,
						'description' 	=> ''
					);
					
					//	OBTIENE LAS CATEGORIAS EXISTENTES
					$categories = $this->db->select('id_categoria, nombre')->from('categorias')->where('calidad',1)->order_by('nombre')->get();
					$this->params['categories'] = $categories->result_array();
					
					//	OBTIENE LOS SERVIDORES ALMACENADOS
					$this->db->select('id_servidor, nombre')->from('servidores');
					$servers = $this->db->get();
					$this->params['servers'] = $servers->result_array();
				/*}
				else{
					$show_error = TRUE;
					$this->params['msg'] = 'Ya has agregado links para este capitulo, para editarlo ve a la opcion "Administrar Mis Series" del Menu';
					$this->params['seo'] = array(
						'title' 		=> ''.Sys::$title_web,
						'description' 	=> $this->params['msg']
					);
				}*/
				
			}else{
				// SI NO EXISTE LA TEMPORADA A LA QUE SE AGREGARA EL EPISODIO
				$show_error = TRUE;
				$this->params['msg'] = 'No existe el Episodio para la Serie seleccionada';
				$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> $this->params['msg']
				);
			}	
		}
		// SI SE EDITA O ACTUALIZA UN EPISODIO
		else if($method === 'edit_episode' || $method === 'update_episode'){
			
			// TITULO DE LA SECCION
			$this->params['lang_txt_seccion'] = lang('txt_seccion_serie_episode_edit');
			// ASIGNA EL ID DEL EPISODIO
			$this->params['episode'] = $params[0];
			$this->params['id_chash'] = $params[1];
			
			$response_errors = $this->validate('get_episode');
			if($this->status){
				
				// CARGA EL MODEL SERIES_MODEL PARA OBTENER LA INFORMACION DEL EPISODIO
				$this->load->model('user_upload_model');
				$episode_info = $this->user_upload_model->getEpisode($this->params);
				
				// SI EL EPISODIO Y SU INFORMACION
				if(is_array($episode_info)){
					
					// $this->params['no_episode']		= $episode_info['no_episode'];
					$this->params['format_episode']	= $episode_info[0]['format_episode'];
					$this->params['quality']		= $episode_info[0]['quality'];
					$this->params['duration']		= $episode_info[0]['duration'];
					$this->params['size']			= $episode_info[0]['size'];
					$this->params['languaje']		= $episode_info[0]['language'];
					$this->params['subtitles']		= $episode_info[0]['subtitle'];
					
					$this->params['url_file']		= $episode_info[0]['fuente_origen'];
					$this->params['url_subtitle']	= $episode_info[0]['url_subtitulos'];
					$this->params['server']	= $episode_info[0]['server'];
					
					
					$this->params['servers_episode']= isset($episode_info['sources']) ? $episode_info['sources'] : null;
					
					// SI EXISTE ALGUN MENSAJE
					if (isset($params['msg_action'])){
						$this->params['class_msg']	= 'msg-ok';
						$this->params['msg_action']	= $params['msg_action'];
					}
		
					// INDICA EL MENU PADRE Y EL SUBMENU QUE SERAN SELECCIONADOS
					$this->params['selected_menu11']	= 'mnu-selected';
					$this->params['selected_submenu33']	= 'submnu-selected';
		
					// EN CASO DE CARGAR EL FORMULARIO SE TIENEN QUE INDICAR ESTOS PARAMETROS LOS CUALES SERAN PARTE DEL ACTION DEL FORMULARIO
					$this->params['controller'] 	= 'users/';
					$this->params['method'] 		= 'update_episode/';
					$this->params['id']				= $this->params['episode'];
					$this->params['idh']			= '/'.$this->params['id_chash'];
		
					$this->params['seo'] = array(
						'title' 		=> ''.Sys::$title_web,
						'description' 	=> ''
					);
					
					//	OBTIENE LAS CATEGORIAS EXISTENTES
					$categories = $this->db->select('id_categoria, nombre')->from('categorias')->where('calidad',1)->order_by('nombre')->get();
					$this->params['categories'] = $categories->result_array();
					
					
					//	OBTIENE LOS SERVIDORES ALMACENADOS
					$this->db->select('id_servidor, nombre')->from('servidores');
					$servers = $this->db->get();
					$this->params['servers'] = $servers->result_array();
					
				}
				else{
					// SI NO EXISTE EL EPISODIO QUE SE QUIERE EDITAR
					$show_error = TRUE;
					$this->params['msg'] = 'El episodio no existe o aun no has agregado tus links';
				}
			}
			else{
				// SI EXISTE ERRORES DE VALIDACION DE LOS PARAMETROS
				$show_error = TRUE;
				$this->params['msg'] = implode(',', $response_errors);
			}
		}

		// SI EXISTE ALGUN ERROR DE VALIDACION
		if($show_error){
			$this->params['seo'] = array(
						'title' 		=> ''.Sys::$title_web,
						'description' 	=> $this->params['msg']
					);
			
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
		}
		else{
			$this->params['aside_extra'] = $this->load->view('interface/panel/films/aside_buttons', $this->params, true);
			$this->load->view('interface/header',$this->params);
			$this->load->view('interface/panel/content',$this->params);
			$this->load->view('interface/panel/user/form_user_add_episode',$this->params);
		}
		
		if($this->params['usr_info']['tipo']==='admin')
			$this->load->view('interface/panel/aside',$this->params);
		elseif($this->params['usr_info']['tipo']==='usuario')
			$this->load->view('interface/panel/user/aside',$this->params);
		
		$this->load->view('interface/footer',$this->params);
		
	}
	
	
	/**
	 *	GUARDA LA INFORMACION ENVIADA DEL FORMULARIO YA SEA SERIE, TEMPORADA O EPISODIO
	 * 
	 * 	@param string $method			METODO QUE LLAMA LA FUNCION
	 * @param array $params				Parametros del Segmento de la URL u otros
	 */
	public function save_episode($method, $params=''){
		
		$this->params['episode'] = $params[0];
		
		// VALIDA LOS PARAMETROS DEPENDIENDO QUE SE GUARDARA SI UNA SERIE, TEMPORADA O EPISODIO
		$response_errors = $this->validate('add_episode');
		
		// INDICA SI EXISTE ALGUN ERROR
		$show_error = FALSE;
		
		// SI NO EXISTE ERRORES EN LOS PARAMETROS VALIDADOS
		if($this->status == TRUE){
			
			// CARGA EL MODEL SERIE_MODEL PARA GUARDAR UNA SERIE, TEMPORADA O EPISODIO
			$this->load->model('user_upload_model');
						
			$episode = $this->user_upload_model->addEpisode($this->params);
			if(is_array($episode))
				// $this->add_episode('save_episode',array( $this->params['episode'] , 'msg_action'=>lang('txt_episode_save_ok'), 't'=>1));
				header('Location:'.Sys::$url_base.$this->params['lang_url'].'panel/users/admin_serie');
			else{
				$this->params['msg'] = lang('txt_season_episode_id_serie_error');
				$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> ''
				);
				$show_error = TRUE;
			}
				
		}else{
			// SI EXISTEN ERRORES DE VALIDACION DE LOS PARAMETROS
			$show_error = TRUE;
			$this->params['msg'] = implode(',', $response_errors);
			$this->params['seo'] = array(
				'title' 		=> ''.Sys::$title_web,
				'description' 	=> $this->params['msg']
			);
		}
		
		// SI EXISTE UN ERROR LOS MUESTRA
		if($show_error){
			$this->carabiner->css('dev/style.css');
			$this->carabiner->css('dev/panel/style.css');
			
			$js	= array(
						array('dev/libs/jquery.js'),
						array('dev/libs/tipsy.js'),
						array('dev/panel/general.js')
					);
					
			$this->carabiner->js($js);
					
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
			
			if($this->params['usr_info']['tipo']==='admin')
				$this->load->view('interface/panel/aside',$this->params);
			elseif($this->params['usr_info']['tipo']==='usuario')
				$this->load->view('interface/panel/user/aside',$this->params);
			$this->load->view('interface/footer',$this->params);
		}
	}
	
	/**
	 *	ACTUALIZA LA INFORMACION ENVIADA DEL FORMULARIO EPISODIO
	 * 
	 * 	@param string $method			METODO QUE LLAMA LA FUNCION
	 * @param array $params				Parametros del Segmento de la URL u otros
	 */
	public function update_episode($method, $params=''){
		
		$this->params['episode'] = $params[0];
		$this->params['id_chash'] = $params[1];
		
		// VALIDA LOS PARAMETROS DEPENDIENDO QUE SE GUARDARA SI UNA SERIE, TEMPORADA O EPISODIO
		$response_errors = $this->validate('add_episode');
		
		// INDICA SI EXISTE ALGUN ERROR
		$show_error = FALSE;
		
		// SI NO EXISTE ERRORES EN LOS PARAMETROS VALIDADOS
		if($this->status == TRUE){
			
			// CARGA EL MODEL SERIE_MODEL PARA GUARDAR UNA SERIE, TEMPORADA O EPISODIO
			$this->load->model('user_upload_model');
			$episode = $this->user_upload_model->updateEpisode($this->params);
			
			if($episode['id_chash'] !== FALSE)
				header('Location:'.Sys::$url_base.$this->params['lang_url'].'panel/users/admin_serie');
				//$this->add_episode('update_episode',array( $this->params['episode'] , 'msg_action'=>lang('txt_episode_update_ok')));
			else{
				$this->params['msg'] = $episode['msg'];
				$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> ''
				);
				$show_error = TRUE;
			}
				
		}else{
			// SI EXISTEN ERRORES DE VALIDACION DE LOS PARAMETROS
			$show_error = TRUE;
			$this->params['msg'] = implode(',', $response_errors);
			$this->params['seo'] = array(
				'title' 		=> ''.Sys::$title_web,
				'description' 	=> $this->params['msg']
			);
		}
		
		// SI EXISTE UN ERROR LOS MUESTRA
		if($show_error){
			$this->carabiner->css('dev/style.css');
			$this->carabiner->css('dev/panel/style.css');
			
			$js	= array(
						array('dev/libs/jquery.js'),
						array('dev/libs/tipsy.js'),
						array('dev/panel/general.js')
					);
					
			$this->carabiner->js($js);
					
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
			
			if($this->params['usr_info']['tipo']==='admin')
				$this->load->view('interface/panel/aside',$this->params);
			elseif($this->params['usr_info']['tipo']==='usuario')
				$this->load->view('interface/panel/user/aside',$this->params);
			$this->load->view('interface/footer',$this->params);
		}
	}
	
	// -----------------------------------------------------------------------------------------------------

	/**
	 * MUESTRA EL FORMULARIO MODIFICAR LA INFORMACION DEL USUARIO
	 * 
	 * @param $method			Metodo que llama la funcion
	 * @param $params			Parametros del Segmento de la URL u otros
	 */
	public function user($method = '', $params=''){
		
		//	CARGA LOS CSS
		$this->carabiner->css('dev/libs/superbox.css');
		// $this->carabiner->css('dev/libs/tipsy.css');
		$this->carabiner->css('dev/style.css');
		$this->carabiner->css('dev/panel/style.css');
		$this->carabiner->css('dev/panel/style_form.css');
		
		//	CARGA LOS JS
		$js	= array(
					array('dev/libs/jquery.js'),
					array('dev/libs/tipsy.js'),
					array('dev/panel/general.js')
				);
		$this->carabiner->js($js);
		
		//	VARIABLE QUE SIRVE PARA INDICAR SI EXISTE ALGUN ERROR DE VALIDACION DE LOS PARAMETROS
		$show_error = FALSE;
		
		//	SI SE EDITA O ACTUALIZA LA INFORMACION DEL USUARIO
		if($method === 'edit_info' || $method === 'update_info'){
			
			$this->load->model('user_model');
			$info = $this->user_model->getInfoUser($this->params);
			$this->params['usr_info'] = $info['user'];
			// echo '<pre>';
			// var_dump($this->params);
			// echo '</pre>';
			
			$this->params['lang_txt_seccion'] = lang('txt_user_edit_info');
			
			$this->params['name']	= $this->params['usr_info']['nombre'];
			$this->params['email']	= $this->params['usr_info']['email'];
			$this->params['user']	=  $this->params['usr_info']['usuario'];
			$this->params['password']	= '';
			$this->params['confirm_password']	= '';
			
			// SI EXISTE ALGUN MENSAJE
			if (isset($params['msg_action'])){
				$this->params['class_msg']	= 'msg-ok';
				$this->params['msg_action']	= $params['msg_action'];
			}

			// INDICA EL MENU PADRE Y EL SUBMENU QUE SERAN SELECCIONADOS
			
			if($this->params['usr_info']['tipo']==='admin')
				$this->params['selected_menu5']	= 'mnu-selected';
			elseif($this->params['usr_info']['tipo']==='usuario')
				$this->params['selected_menu1']	= 'mnu-selected';
			
			$this->params['selected_submenu0']	= 'submnu-selected';

			// EN CASO DE CARGAR EL FORMULARIO SE TIENEN QUE INDICAR ESTOS PARAMETROS LOS CUALES SERAN PARTE DEL ACTION DEL FORMULARIO
			$this->params['controller'] 	= 'users/';
			$this->params['method'] 		= 'update_info/';
			$this->params['id']				= '';

			$this->params['seo'] = array(
				'title' 		=> ''.Sys::$title_web,
				'description' 	=> ''
			);
			
			// else{
				// $show_error = TRUE;
				// $this->params['msg'] = lang('txt_serie_active_id_update_error');
				// $this->params['seo'] = array(
					// 'title' 		=> ''.Sys::$title_web,
					// 'description' 	=> $this->params['msg']
				// );
			// }		
		}

		if($show_error){
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
			$this->load->view("interface/panel/aside", $this->params);
			$this->load->view("interface/footer", $this->params);
		}
		else{			
			$this->params['aside_extra'] = $this->load->view('interface/panel/films/aside_buttons', $this->params, true);
			$this->load->view('interface/header',$this->params);
			$this->load->view('interface/panel/content',$this->params);
			$this->load->view('interface/panel/user/form_user_data',$this->params);
			
			if($this->params['usr_info']['tipo']==='admin')
				$this->load->view('interface/panel/aside',$this->params);
			elseif($this->params['usr_info']['tipo']==='usuario')
				$this->load->view('interface/panel/user/aside',$this->params);
			
			$this->load->view('interface/footer',$this->params);
		}
	}
	
	/**
	 *	ACTUALIZA LA INFORMACION DEL USUARIO
	 * 
	 * 	@param string $method			METODO QUE LLAMA LA FUNCION
	 * @param array $params				Parametros del Segmento de la URL u otros
	 */
	public function update($method, $params=''){
		
		// VALIDA LOS PARAMETROS DEPENDIENDO QUE SE GUARDARA
		$response_errors = $this->validate('edit');
		
		// INDICA SI EXISTE ALGUN ERROR
		$show_error = FALSE;
		
		// SI NO EXISTE ERRORES EN LOS PARAMETROS VALIDADOS
		if($this->status == TRUE){
			
			$this->load->model('user_model');
			$user = $this->user_model->updateInfoUser($this->params);

			if($user!=FALSE)
				$this->user('update_info',array('msg_action'=>lang('txt_user_update_info_ok')));
			else{
				$show_error = TRUE;
				$this->params['msg'] = 'Error...';
				$this->params['seo'] = array(
					'title' 		=> ''.Sys::$title_web,
					'description' 	=> $this->params['msg']
				);
			}
		}else{
			// SI EXISTEN ERRORES DE VALIDACION DE LOS PARAMETROS
			$show_error = TRUE;
			$this->params['msg'] = implode(',', $response_errors);
			$this->params['seo'] = array(
				'title' 		=> ''.Sys::$title_web,
				'description' 	=> $this->params['msg']
			);
		}
		
		// SI EXISTE UN ERROR LO MUESTRA
		if($show_error){
			$this->carabiner->css('dev/style.css');
			$this->carabiner->css('dev/panel/style.css');
			
			$js	= array(
						array('dev/libs/jquery.js'),
						array('dev/panel/general.js')
					);
					
			$this->carabiner->js($js);
					
			$this->load->view("interface/header", $this->params);
			$this->load->view("interface/errors/page_error", $this->params);
			$this->load->view("interface/panel/aside", $this->params);
			$this->load->view("interface/footer", $this->params);
		}
	}
	
	/**
     * Permite incorporar las validaciones bases que apliquen para todos los servicios.
     * Validaciones mas espesificas tendran que ser en cada servicio en particular.
     * @author gama
     */
    protected function validate($val_method){
    	if(method_exists($this, 'validate_'.$val_method)){
    		$this->load->library('MY_Form_validation');
    		return $this->{'validate_'.$val_method}();
    	}
    }
	
	private function validate_add_film(){
		
		$validate = new MY_Form_validation();
		$validate->setArrayValidate($this->params);

		$config	= array(
							array(
									'field'	=> 'sel-servers[]',
									'label'	=> 'sel-servers',
									'rules'	=> 'required|is_natural_no_zero'
							),
							array(
									'field'	=> 'languaje',
									'label'	=> 'languaje',
									'rules'	=> 'required|max_length[20]'
							),
							array(
									'field'	=> 'subtitle',
									'label'	=> 'subtitle',
									'rules'	=> 'required|max_length[20]'
							),
							array(
									'field'	=> 'format_film',
									'label'	=> 'format_film',
									'rules'	=> 'required|max_length[10]'
							),
							array(
									'field'	=> 'quality',
									'label'	=> 'quality',
									'rules'	=> 'required|is_natural_no_zero'
							),
							array(
									'field'	=> 'duration',
									'label'	=> 'duration',
									'rules'	=> 'required|max_length[30]'
							),
							array(
									'field'	=> 'size',
									'label'	=> 'size',
									'rules'	=> 'required|max_length[20]'
							),
							array(
									'field'	=> 'url_torrent[]',
									'label'	=> 'url_torrent',
									'rules'	=> 'required|max_length[250]'
							),
							array(
									'field'	=> 'url_subtitle[]',
									'label'	=> 'url_subtitle',
									'rules'	=> 'max_length[200]'
							)
					);
		
		$validate->set_rules($config);
		$this->status = $validate->run();
		
		//	VALIDA QUE LAS URLS DEL TORRENT Y SUBTITUTLOS SEAN VALIDAS	
		/*if($this->status){
			if(!sys::urlValid($this->params['url_torrent'])){
				$this->status = FALSE;
				$validate->_error_array['values'] = lang('txt_invalid_url','ARCHIVO');
			}
			if(!sys::urlValid($this->params['url_subtitle'])){
				$this->status = FALSE;
				$validate->_error_array['values'] = lang('txt_invalid_url','SUBTITULO');
			}
		}*/
		
		//	VALIDA QUE LA URL DEL $PARAMS['SCREENSHOTS'] SEA VALIDA.
		// if(isset($this->params["screenshots"]) && !empty($this->params['screenshots'])){
			// $url = $this->params['screenshots'];
			// if(!sys::urlValid($url)){
    			// $this->status = FALSE;
    			// $validate->_error_array['values'] = lang('txt_invalid_url', 'screenshots => "'.$url.'"');
			// }
    	// }
		
		return $validate->_error_array;
	}
	
	
	
	 private function validate_edit(){
    $validate = new MY_Form_validation();
    	$validate->setArrayValidate($this->params);
    	
    	$validate->set_rules(array(
    			array('field' => 'name', 
                     'label' => 'name', 
                     'rules' => 'required|max_length[50]'),
    			array('field' => 'email', 
                     'label' => 'email', 
                     'rules' => 'required|valid_email|max_length[70]'),
    			array('field' => 'password',
                     'label' => 'password', 
                     'rules' => 'min_length[6]|max_length[32]'),
    			array('field' => 'confirm_password', 
                     'label' => 'confirm_password', 
                     'rules' => 'max_length[32]'),
                     
				array('field' => 'user', 
                     'label' => 'user', 
                     'rules' => 'max_length[15]')
    	));
    	$this->status = $validate->run();
    	
    	if(isset($this->params["confirm_password"])){
    		if($this->params["confirm_password"] != $this->params["password"]){
    			$this->status = false;
    			$validate->_error_array['values'] = lang('txt_password_confirm');
    		}
    	}
    	
    	return $validate->_error_array;
    }

	private function validate_get_film(){
		$validate	= new MY_Form_validation();
		$validate->setArrayValidate($this->params);
		
		$config = array(
							array(
								'field' => 'id_film',
								'label' => 'id_film',
								'rules' => 'required|is_natural_no_zero'
							)
		);
		$validate->set_rules($config);
		$this->status = $validate->run();
		
		return $validate->_error_array;
		
	}

	protected function validate_search(){
		$validate = new MY_Form_validation();
    	$validate->setArrayValidate($this->params);
    	
    	$validate->set_rules(array(
    			array(
    				'field' => 'q',
					'label' => 'q',
					'rules' => 'required')
    	));
    	$this->status = $validate->run();
    	return $validate->_error_array;
	}

	private function validate_add_episode(){
    	$validate = new MY_Form_validation();
    	$validate->setArrayValidate($this->params);
    	
    	$validate->set_rules(array(
    			array('field'	=> 'sel-servers[]',
					  'label'	=> 'sel-servers',
					  'rules'	=> 'required|is_natural_no_zero'),
				array('field' => 'format_episode', 
                     'label' => 'format_episode', 
                     'rules' => 'required|max_length[10]'),
				array('field' => 'quality', 
                     'label' => 'quality', 
                     'rules' => 'required|is_natural_no_zero'),
				array('field' => 'duration', 
                     'label' => 'duration', 
                     'rules' => 'required|max_length[30]'),
				array('field' => 'size', 
                     'label' => 'size', 
                     'rules' => 'required|max_length[20]'),
				array('field' => 'languaje', 
                     'label' => 'languaje', 
                     'rules' => 'required|max_length[20]'),
				array('field' => 'subtitles', 
                     'label' => 'subtitles', 
                     'rules' => 'required|max_length[20]'),
				array('field'	=> 'url_torrent[]',
					  'label'	=> 'url_torrent',
					 'rules'	=> 'required|max_length[250]'),
				array('field'	=> 'url_subtitle[]',
					  'label'	=> 'url_subtitle',
				      'rules'	=> 'max_length[200]')
				
    	));
		$this->status = $validate->run();
		
		//	VALIDA QUE LAS URLS DEL TORRENT Y SUBTITUTLOS SEAN VALIDAS	
		/*if($this->status){
			if(!sys::urlValid($this->params['url_torrent'])){
				$this->status = FALSE;
				$validate->_error_array['values'] = lang('txt_invalid_url','ARCHIVO');
			}
			if(!sys::urlValid($this->params['url_subtitle'])){
				$this->status = FALSE;
				$validate->_error_array['values'] = lang('txt_invalid_url','SUBTITULO');
			}
		}*/
    	return $validate->_error_array;
    }
	
	private function validate_get_episode(){
    	$validate = new MY_Form_validation();
    	$validate->setArrayValidate($this->params);
    	
    	$validate->set_rules(array(
    			array('field' => 'episode', 
                     'label' => 'episode', 
                     'rules' => 'required|is_natural_no_zero')
    	));
		$this->status = $validate->run();
		return $validate->_error_array;
    }
	
}